package pack1;

import java.util.Arrays;

public class SheelSort {
    public static void main(String[] args) {
        int[]arr={3,5,6,88,99,2,1,5};
        int[]arr2={9,8,7,6,5,4,3,2,1};
        sheelSort(arr);
        sheelSort(arr2);
        System.out.println(Arrays.toString(arr));
        System.out.println(Arrays.toString(arr2));

    }

    public static void sheelSort(int[]arr){
        int grap=arr.length/2;
        while(grap>1){
            sheel(arr,grap);
            grap/=2;
        }
        InsertSort.insertSort(arr);
    }

    public static void sheel(int[]arr,int grap){
        for (int i = grap; i < arr.length; i++) {
            int j;
            int temp=arr[i];
            for (j=i-grap; j>=0; j-=grap) {
                if(arr[j]>temp){
                    arr[j+grap]=arr[j];
                }else{
                    arr[j+grap]=temp;
                    break;
                }
            }
            arr[j+grap]=temp;
        }
    }
}
